Prizm Content Connect
MVC Sample

The MVC sample is similar to the HTML5 C# and VB sample project but edited and rearranged to follow the Model Viewer Control (MVC) 4 architectural layout. This sample illustrates a solution that follows a MVC design but is not necessarily the best way or only way to implement the solution but is only intended to illustrate how the HTML5 solution does fit with a MVC approach.

In this sample, the communication between the client and the MVC service side employs the Web API Controller class (i.e., inherits from ApiController). The routing of the client PccViewer control requests are mapped in the WebApiConfig.cs file as illustrated in the following:

Example
Copy Code
           config.Routes.MapHttpRoute(
                name: "DefaultPccApi",
                routeTemplate: "PCC.ashx/{controller}/{*urlTemplate}"

where
controller will normally be mapped to one of three controllers:
1)  DocumentController
2)  PageController
3)  LicenseController

And
*urlTemplate accepts the remaining URL portions which direct it to the appropriate method call. See Pcc.cs for additional details.

Each mapping calls into the appropriate controller as noted above where the PccConvert class objects refines the mapping to a method.  This mechanism will be discussed below.

Like the HTML5 Sample, the MVC sample also implements the objects from the PccViewerServices Library Module but puts other class objects into the PccMvcSample namespace and below (e.g. PccMvcSample.App_Code, PccMvcSample.Controllers).

One significant difference from the HTML5 sample is the missing Default.aspx page which has been replaced by the Index.cshtml view page. Although, this change is not absolutely necessary as the Default.aspx page could still be used if desired. The other missing file difference is the PCC.ashx file which has been incorporated into the Pcc.cs file and still plays the same role as matching the Uniform Resource Indicator (URI) addresses to the appropriate methods for servicing the client PccViewer control requests. The PccViewer client controls use the RESTful methodology as described in the Developers Guide Section on RESTful API.  

To keep development simple, the PccConvert class object in Pcc.cs will match the PccViewer requests and invoke the appropriate method call. Thus the three controllers: DocumentController, PageController and LicenseController use the PccConvert class object to accomplish the request received from the client controller. The following code snippet illustrates the common scheme used to process the client request in all three controllers:

Example
Copy Code
       // GET api/page
        public HttpResponseMessage Get()
        {
            PccConfig.LoadConfig("prizmconfig.xml");

            HttpContext context = System.Web.HttpContext.Current;
            PccConvert pcc = new PccConvert();
            pcc.ProcessRequest(context);
            return new HttpResponseMessage((HttpStatusCode)context.Response.StatusCode);
        }

From that point, the code sequence is pretty similar to the HTML5 .NET sequence.  

As previously mentioned, the index.cshtml is the default web page in the MVC model sample presented here. The differences are the expected differences from a Razor page view versus the traditional ASPX page view. A Default.aspx page could have been explicitly called out in the URI and it would still perform correctly.

Configuring the MVC Sample

To start a new application begin with creating a new fresh MVC 4 Web Application project which lays out a typical MVC configuration with all the necessary files within the packages directory inherent to a MVC sample. 

In this particular project, choose a Web API template. However, since the template provides a quick startup sample, much of it can be discarded unless you know you will need a specific style sheet .css file or JavaScript file. The PCC product is designed with jQuery-1.7.2 and uses a number of its own JavaScript files. So, the Script directory should be replaced by the PCC MVC sample js folder or make the appropriate sample code references changes back to the script folder. 

In this sample, BundleConfig.cs file in the App_Start directory bundles the required JavaScript files for the MVC sample from the js folder and likewise the cascading style sheets from the css folder. The images folder has been modified to contain the PccViewer image objects and the extra MVC template images removed.  In the Controllers directory, the HomeController.cs file is kept but the other template controller samples were discarded. 

The MVC sample added three Web API controllers to this Controllers folder.  A new App_Code folder was added containing the PCC class objects. Be careful to ensure that the files here are added with the Build Action set to Compile versus as the default Content setting for this property. Naturally, the Index.cshtml file in the Home folder off the Views folder needs to be changed and so does the _layout.cshtml file in the Shared folder. The following table detail the significant changes: 

File

Description

App_Code Folder

Contains the supporting classes for environmental configuration and the RESTful communication scheme between the pccViewer and web tier service. While the code body for the classes can be modified as needed, the APIs modifications need careful management if changed. These modules provide the called from the Web API controllers noted below.

App_Start Folder

Contains the necessary configuration files started by the MVC application to setup conditions prior to executing the application functionality. BundleConfig.cs and WebApiControl.cs are edited to accomplish the PCC services.

Controllers Folder

MVC folder to house the typical MVC control modules. The Web API control modules are here as well for PccViewer client to server request control. The three PCC Web API controllers are DocumentController.cs, PageController.cs and LicenseController.cs.

Views Folder

Provides the MVC view code portion. The default index view file, Index.cshtml, contains the Razor version of the Default.aspx page used in the HTML 5 C# and VB samples. The _Layout.cshtml changes in the sample ties in the PCC css files and JavaScript files.

PccViewerServices

Assembly shared by vb, c# and MVC samples. Source is in a separate directory and moves the communication backend between the web tier and imaging services (proxy server) into its own namespace and class objects. See the PccViewerServices topic for details.

Js folder

Contains the required Javascript files making up the pccViewer entity.

Images folder

Graphics for pccViewer.

Css folder

Web style sheet for the pccViewer.

Global.asax (and .cs)

Standard ASP.NET Web framework file that handles application and session-level events and objects.

PccConfig.cs

File which assists in providing environmental parameters from the prizmconfig.xml to the PCC application.

Packages.config

The MVC package list for this sample. The packages folder must be populated with the appropriate objects called out in this list.

Prizmconfig.xml

Contains modifiable parameter content locations for documents, cache folder and proxyserver connection.

Web.config

Contains IIS and web tier settings.

Sample.doc

For the HTML5 sample, the test document used to illustrate the functional prizm content connect product.

With all these pieces, a web application page can be put together using a query parameter to pass in the document to be viewed. The following HTML5 sample illustrates a simple web default index view (application solution using the document parameter for the query string to get the document to view):

MVC 4 Default view web code (Index.cshtml)

Copy Code
<header>
  <div>
    <b>
       Prizm Content Connect MV4 Sample
    </b>
  </div>
</header>
<divid="body">
   @{
     PccMvcSample.PccConfig.LoadConfig("prizmconfig.xml");


     string document;
     document = Request.QueryString["document"];

     if (document == null)
     {
       @Html.Raw("You must include the name of a document in the URL.<br/>");
       @Html.Raw("For example, click this link: ")<a href="\?document=sample.doc">/?document=sample.doc</a>
       return;
     }

     string documentLocation = PccMvcSample.PccConfig.DocumentFolder;
     string tempLocation = PccMvcSample.PccConfig.TempFolder;
     string attlist = "";
     string originalDocument = System.IO.Path.Combine(documentLocation, document);

     bool correctPath =
     PccViewerServices.ServiceLocator.Singleton.ApplicationConfig.IsFileSafeToOpen(originalDocument);
     if (!correctPath)
     {
       Response.Clear();
       Response.Write("<h1>403 Forbidden</h1>");
       Response.StatusCode = (int)System.Net.HttpStatusCode.Forbidden;
       return;
     }
    
     string extension = System.IO.Path.GetExtension(originalDocument).ToLower();
     string filename = System.IO.Path.GetFileName(originalDocument);

     
     if (extension.Equals(".msg") || extension.Equals(".eml"))
     {
       // Get list of attachments
       string attachmentslist = PccMvcSample.PccConfig.ImagingService + "/convert2swf?source=" +
         HttpUtility.UrlEncode(originalDocument) + "&getattachments";
       System.Net.WebRequest requesturl = System.Net.HttpWebRequest.Create(attachmentslist);
       requesturl.Method = System.Net.WebRequestMethods.Http.Get;
       System.Net.WebResponse serviceresponseurl = requesturl.GetResponse();
       System.IO.StreamReader readerurl = new System.IO.StreamReader(serviceresponseurl.GetResponseStream());
       attlist = readerurl.ReadToEnd();
       serviceresponseurl.Close();

       if (attlist.Length == 2)
       {
         // If no attachments list found, no extraction of attachments needed
       }
       else
       {
         // Extract attachments into tempcache
         String attachmentsextracturl = PccMvcSample.PccConfig.ImagingService +
           "/convert2swf?source=" +
            HttpUtility.UrlEncode(originalDocument) + "&target=" +
            HttpUtility.UrlEncode(tempLocation) +
            "&extractttachments";
         System.Net.WebRequest requesturl1 =
             System.Net.HttpWebRequest.Create(attachmentsextracturl);
         requesturl1.Method = System.Net.WebRequestMethods.Http.Get;
         System.Net.WebResponse serviceresponseurl1 = requesturl1.GetResponse();
         var readerurl1 = new System.IO.StreamReader(serviceresponseurl1.GetResponseStream());
         String attlist1 = readerurl1.ReadToEnd();
         serviceresponseurl1.Close();
       }
     }


  }
  <script type="text/javascript">
    var documentName1 = '@HttpUtility.UrlEncode(document)'
    $(document).ready(function () {
      var pluginOptions1 = { documentID: documentName1, toolboxMenuOpen: false, annotationID: 'Annotation Filename', uiElements: { toolTips: true, fullScreenToggle: true, firstLastPage: false} }
      $("#imageGearPageView").pccViewer(pluginOptions1);
    });
  </script>
  @{
    if (extension.Equals(".msg") || extension.Equals(".eml"))
    {

      if (attlist.Length == 2)
      {
        //No Attachments in the email message
      }
      else
      {
        @Html.Raw("<b>File Type: Email Message Format</b><br />");
        @Html.Raw("<br />");
        @Html.Raw("<b>Attachments:</b><br />|");
        string[] attlistarray = attlist.Split(',');
        // Use For Each loop over words and display them
        for each (string att in attlistarray)
        {
          string url = HttpUtility.UrlEncode(System.IO.Path.Combine(tempLocation +
              System.IO.Path.DirectorySeparatorChar + filename + ".att", att.Trim()));          
          @Html.Raw("&nbsp;<a href=\"\\?document=")@url@Html.Raw("\\")@att@Html.Raw("\"></a>&nbsp;");
        }
      }
     }
    }  
     
   <div>
    <p>
      <b>Quick FAQ Link:</b> <a href="http://www.accusoft.com/prizmfaq.htm" target="_blank">
        http://www.accusoft.com/prizmfaq.htm</a>
    </p>
    <p>
      Verify that these parameters are correctly set, if you cannot see the document loaded
      below.<br />
    </p>
    <p>
      <b>Document Location: <a href="@Request.Url.AbsoluteUri"> @Request.Url.AbsoluteUri</a></b>
       <br />
      <b>Server Document Location:</b>
      @documentLocation<br />
      <b>Full Document Path:</b>
      @originalDocument
      <br />
      <b>Temp Location:</b>
      @tempLocation<br />
      <b>Annotations:</b>
      @PccMvcSample.PccConfig.MarkupFolder<br />
      <br />
    </p>
  </div>
  <div id="imageGearViewer">
    <div id="imageGearPageView">
    </div>
  </div>
</div>

 

BundleConfig.cs

Copy Code
namespacePccMvcSample
{
  public class BundleConfig
  {
    // For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725
    public static void RegisterBundles(BundleCollection bundles)
    {
      bundles.IgnoreList.Clear();
      bundles.Add(new ScriptBundle("~/bundles/jquery").Include("~/js/jquery-1.7.2.min.js"));
      bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include("~/js/jquery-ui-1.8.21.custom.min.js"));

      bundles.Add(new ScriptBundle("~/bundles/imagegear").Include(
        "~/js/ImGearPlugins.js", "~/js/Core.js", "~/js/ClientViewer.js","~/js/ClientArt.js",
        "~/js/ThumbnailList.js"));

      bundles.Add(new ScriptBundle("~/bundles/pccviewer").Include("~/js/pccViewer.js"));

      bundles.Add(new ScriptBundle("~/bundles/pccprint").Include("~/js/pccPrint.js"));

      bundles.Add(new StyleBundle("~/pcc/css").Include(
        "~/css/pcc.css","~/css/pcc-viewer-jquery-ui-1.8.23.css"));

     }
  }
}

 

 

 


©2014. Accusoft Corporation. All Rights Reserved.

Send Feedback